package com.ourteam.system.api;

import org.apache.commons.lang.StringUtils;

import com.ourteam.frame.web.AbstractSearchModel;
import com.ourteam.system.dao.ISysEventLogDAO;
import com.ourteam.system.dao.SysEventLogDAOQueryBean;
import com.ourteam.system.domain.SystemEventLogBean;

public class SystemEventLogSearchModel extends AbstractSearchModel<SysEventLogDAOQueryBean> {

	private String eventSource;

	private Long eventSourceId;

	private Long operatorId;

	private Long eventTypeId;

	public String getEventSource() {
		return eventSource;
	}

	public void setEventSource(String eventSource) {
		this.eventSource = eventSource;
	}

	public Long getOperatorId() {
		return operatorId;
	}

	public void setOperatorId(Long operatorId) {
		this.operatorId = operatorId;
	}

	public Long getEventTypeId() {
		return eventTypeId;
	}

	public void setEventTypeId(Long eventTypeId) {
		this.eventTypeId = eventTypeId;
	}

	public Long getEventSourceId() {
		return eventSourceId;
	}

	public void setEventSourceId(Long eventSourceId) {
		this.eventSourceId = eventSourceId;
	}

	@Override
	public String getMappedDAOField(String aProperty) {

		return SystemEventLogBean.getMappedDAOField(aProperty);
	}

	@Override
	protected void doBuildQueryBean(SysEventLogDAOQueryBean queryBean) throws Exception {

		SysEventLogDAOQueryBean.Criteria criteria = queryBean.createCriteria();

		if (StringUtils.isNotBlank(eventSource)) {
			criteria.andEventSourceEqualTo(eventSource);
		}

		if (eventSourceId != null && eventSourceId != 0) {
			criteria.andEventSourceIdEqualTo(eventSourceId);
		}

		if (operatorId != null && operatorId != 0) {
			criteria.andEventOperatorIdEqualTo(operatorId);
		}

		if (eventTypeId != null && eventTypeId != 0) {
			criteria.andEventTypeIdEqualTo(eventTypeId);
		}

		if (queryBean.getSortProperties().isEmpty()) {
			queryBean.setSortProperty(ISysEventLogDAO.EventTime, false);
		}

	}

}
